import PeripheralSystemDataMgr from "./PeripheralSystemDataMgr";
import EngineUtil from "./EngineUtil";
import BasePageCtrl, { AnimType } from "./BasePageCtrl";
import UiManage from "./UiManage";
import FundWithDrawConditionPage from "./FundWithDrawConditionPage";

const { ccclass, property } = cc._decorator;

@ccclass
export default class FundWithDrawConditionPageCtrl extends BasePageCtrl {
    @property
    ui: FundWithDrawConditionPage = null;

    p = [
        "<b><color=#785740>到达第</color><color=#FF3A17>cityid</color><color=#785740>个城市</color><color=#FF3A17>cityName</color><color=#785740>即可提到微信</color>\n<color=#785740>当前在第</color><color=#FF3A17>curCity</color><color=#785740>个城市</color></b>",
        "<b><color=#785740>累计打卡</color><color=#FF3A17>clickDay</color><color=#785740>天即可提到微信，还差</color><color=#FF3A17>needDay</color><color=#785740>天</color></b>",
    ];

    onLoad() {
        this.onUILoad();
        this._animType = AnimType.SCALE;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        super.onLoad();
        this.addButtonListen();
    }

    start() {}

    _init(e?) {
        if (e) {
            const t = e.conditional;
            const a = e.type;
            const o = e.gold_balance;
            let i = this.p[a - 1];
            const r = t.current;
            const s = t.finish;
            const c = t.need;
            const u = PeripheralSystemDataMgr.getCityNameByCityId(s - 1);
            if (a === 1) {
                i = i.replace(/cityid/g, s.toString()).replace(/cityName/g, u).replace(/curCity/g, r.toString());
            } else {
                i = i.replace(/clickDay/g, s.toString()).replace(/needDay/g, c);
            }
            this.ui.cashNode.getComponent(cc.Label).string = EngineUtil.getCashBalance(o) + "元";
            this.ui.descNode.getComponent(cc.RichText).string = i;
            this.ui.pro.getComponent(cc.Sprite).fillRange = r / s;
            this.ui.proLabel.getComponent(cc.Label).string = `${r}/${s}`;
        }
    }

    onUILoad() {
        this.ui = this.node.addComponent(FundWithDrawConditionPage);
    }

    addButtonListen() {
        UiManage.addButtonListen(this.ui.btn_close, this.clickClose, this);
        UiManage.addButtonListen(this.ui.btn_continue, this.clickClose, this);
    }

    clickClose() {
        this.hide();
    }
}
